import React from 'react';
import { connect } from 'dva';
import { Switch } from 'antd';
import style from './index.less';

class Receipt extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
     checked:true,
    };
    this.handleSwitchChange = this.handleSwitchChange.bind(this);
  }

   handleSwitchChange(checked) {
    this.setState({
      checked: checked,
    })
  }

  render() {
    const data = this.props.data.token_id ? this.props.data : JSON.parse(this.props.data);
    const formatted = JSON.stringify(data, null, 4);
    return (
      <div className={style.normal}>
        <div className={style.title}>
          <span className={style.text}>{ this.props.data.token_id ? '发币信息': '存证信息'}</span>
          <Switch checkedChildren="格式化JSON" unCheckedChildren="格式化JSON" defaultChecked onChange={this.handleSwitchChange} />
        </div>
        <div className={style.json}>
          <pre>{this.state.checked ? formatted : this.props.data}</pre>
        </div>
      </div>
    )
  }
}



export default Receipt;
